package 面试.遍历算法.String类型题目;

public class 统计字母或数字次数 {
    public static void main(String[] args) {
        String str="abc23s2%$*";
        int num1 = 0,num2 = 0,num3 = 0;
        for (int i = 0; i < str.length(); i++) {
            String str1 = str.charAt(i) + "";
            if(str1.matches("[a-zA-Z]")){
                num1 ++;
            }else if(str1.matches("[0-9]")){
                num2 ++;
            }else {
                num3 ++;
            }
        }
        System.out.println("字母：" + num1 + "，数字：" + num2 + ",其它：" + num3);
    }
}
